<%@ LANGUAGE="VBSCRIPT" %>
<%'  ------------------------------------------------------------
  '  adddoccontent.asp 
  '  ------------------------------------------------------------
  '  VCS INFO:
  '  
  '  $Revision:   1.38  $
  '  $Date:   17 Nov 2000 16:59:22  $
  '  $Author:   vpham  $
  '  $Workfile:   adddoccontent.asp  $
  '  ------------------------------------------------------------
  '  All Rights Reserved.  Copyright (c) 1988-1998 FileNET Corp.
  '  ------------------------------------------------------------
  '%>
<!-- #include file="islogon.asp" -->
<!-- #include file="jscriptfix.asp" -->
<!-- #include file="notimpl.asp" -->
<!-- #include file="convtohints.asp" -->
<%
    '
    ' Get User/Session Info
    '
    DebugFlag = 0
    ObjType = Application("idmObjTypeDocument")
    RequestMethod = Request.ServerVariables("REQUEST_METHOD")
    if RequestMethod = "POST" then
        Ident = Request.Form("Ident")
        Update = Request.Form("Update")
        ShowHints = Request.Form("ShowHints")
    else
        Ident = Request.QueryString("Ident")
        Update = Request.QueryString("Update")
    end if
    if not IsNull(ShowHints) then
      if ShowHints = "on" then
        Session("ShowHints") = 1
      else 
        Session("ShowHints") = 0
      end if
    end if
    
    ShowHintsFlag = Session("ShowHints")
    'Panagon IDM Web application uses the Session variable LibraryLogonID to keep track of
    'whether the user has logged on.
    'Please see logoncall.asp to see how the Session variable LibraryLogonID is set.
    LibraryLogonID = Session("LibraryLogonID")
    set LibraryObj = Server.CreateObject("IDMObjects.Library")
    LibraryObj.LogonID = LibraryLogonID
    '
    ' Validate that this is an IDM Document Services and not an IDM Image Services 
    '
    ' For now, we're only supporting adding to IDM Document Services.
    '
    '
    if LibraryObj.SystemType = Application("idmSysTypeIS") then
%>


<HTML>
    <HEAD>
        <TITLE>EDM-specific page</TITLE>
    </HEAD> 
    <BODY>
    <H2>Redirecting to property screen</H2>
    You are currently logged into an IDM Image Services Library and trying to use a Document Services specific page.
    </BODY>
</HTML>
<%
    '
    ' We don't want to display any more, because we're on the wrong page
    '
    Response.End
    end if
    '
    ' Now we hit the first stage of adding a document, choosing the doc class
    '
    ' Test to see if we already have a doc class
    '
    DocClass = Request("doctype")
    if Len(DocClass) = 0 then
    '
    ' We don't have a docclass, display the choose doc class form.
    '
%>
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html">
<meta name="GENERATOR" content="">
<title>Add Document: Choose a DocType</title>
</head>
<body bgcolor="#FFFFFF">
<%
    set objClasses = LibraryObj.FilterClassDescriptions( Application("idmObjTypeDocumentSecure"))
%>

<font size="+1"><strong>Select the document type</strong></font><br>
<strong><em>Add document to library '<%= Server.HTMLEncode(LibraryObj.Label) %>.'</em></strong>
<form name="docclassform" action="adddoccontent.asp" method="POST">
<strong> <em>Please select the type of the document to add: </em> </strong>
<select name="doctype" onChange="document.docclassform.submit()">
            <option value="">&lt;Choose a type&gt;</option>
        <%
        ' enumerate through the DocType list, to provide the selection list 
        for each objClass in objClasses%>
            <option value="<%=objClass.Name%>"><%=Server.HTMLEncode(objClass.Name)%></option>
        <%next%>
</select>
</form>
</body>
</html>
<%
    Response.end  
    end if
    '
    ' We have a doc class, check whether we need to enter properties
    '
    set DocTypes = LibraryObj.FilterClassDescriptions( Application("idmObjTypeDocument"))
    set DocType = DocTypes(1) ' default
    for i = 1 to DocTypes.Count
        if DocTypes(i).Label = DocClass then
            set DocType = DocTypes(i)
        end if
    next
    HaveProps = Request("submitProps")
    if Len(HaveProps) = 0 or HaveProps <> "1" then
    '
    ' We have to enter some properties before we can add the document.
    '

%>

<SCRIPT LANGUAGE="JavaScript">
<!--
// call MultiValue Property Page 
function MayPickMVProperty(docid, propName, ObjType)
{

  // location.href = "mz_MVPMayPick.asp?Type="+ObjType+"&Ident=" + docid + "&PropIndex=" + index;
    document.propenter.PropToModify.value=propName;
    document.propenter.submitProps.value = "0";
    document.propenter.SubmitFlag.value = "0";
    document.propenter.UpdateFlag.value = "0";
    document.propenter.action = "mz_newMVProp.asp";
    document.propenter.submit();
}

//-->
</SCRIPT>

<SCRIPT LANGUAGE="JavaScript">
<!--
// Show Hints flag used to display info on each property data type
function ShowPropertyHints()
{
    document.propenter.submitProps.value = "0";
    document.propenter.SubmitFlag.value = "0";
    document.propenter.UpdateFlag.value = "0";
    if (document.propenter.formloaded.value =="1")
    {
        document.propenter.submit();
    } else {
        document.docreload.submit();
    }
}
//-->
</SCRIPT>

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html">
<meta name="GENERATOR" content="">
<title>Add Document: Enter Document Properties</title>
</head>


<body bgcolor="#FFFFFF">
<font size="+2"><strong>Enter Properties</strong></font><br>
<strong><em>Add document to library '<%= Server.HTMLEncode(LibraryObj.Label) %>' with doc type '<%= Server.HTMLEncode(DocClass) %>.'</em></strong>

<FORM NAME="docreload" ACTION="adddoccontent.asp" METHOD="POST">
<!-- begin hidden parameters 
   - these parameters are passed to the actual add isapi dll-->
<% for each x in Request.Form
    PropName = x
    for i = 1 to Request.Form(x).Count 
    PropValue= Request.Form(x).item(i) 
%>
            <input type=hidden name="<%=PropName%>" value="<%=PropValue%>">
<%
    next 
   next %>
</FORM>


<form name="propenter" action="adddoccontent.asp" method="POST">
<input type="hidden" name="submitProps" value="">
<input type="hidden" name="formloaded" value="0">
<input type="hidden" name="SubmitFlag" value="0">
<input type="hidden" name="PropIndex" value="">
<input type="hidden" name="PropToModify" value="">
<input type="hidden" name="UpdateFlag" value="1">
<input name=doctype type=hidden value="<%=DocClass%>">
<table border="0" cellpadding="0" cellspacing="1">
    <tr>
    <td>&nbsp;</td>
    <td colspan=4>
    <input type="checkbox" name="ShowHints" language="JavaScript" onclick="ShowPropertyHints()"
        <% if ShowHintsFlag then %>checked<% end if %>><font size=2>Show Property Hints</font>
    </td>
    <!-- <td align=right nowrap>
        <% if not IsVirtual then %><input type="radio" name="Validate" language="JavaScript" OnClick="ValidateProps()"><font size=2>Validate Now</font><% end if %>
    </td> -->
    </tr>
</table>
<br>
<% IEBrowser = InStr(Request.ServerVariables("HTTP_USER_AGENT"), "MSIE")
if IEBrowser then %>
<table frame="box" rules="groups" border="1" cellpadding="0" cellspacing="1">
<% else %>
<table frame="box" rules="groups" border="0" cellpadding="0" cellspacing="1">
<% end if %>
<COLGROUP>
    <COL SPAN="3" ALIGN="left">
<COLGROUP>
    <COL SPAN="3" ALIGN="left">
<THEAD>
    <tr>
        <td align="center" width="30" bgcolor="#EECCFF">&nbsp;</td>
        
        <td align="center" bgcolor="#EECCFF">&nbsp;</td>
        <td align="center" width="200" bgcolor="#EECCFF"><font
        size="3"><strong>Property</strong></font></td>
        <td align="center" width="200" bgcolor="#EECCFF"><font
        size="3"><strong>Value</strong></font></td>
        <td align="center" width="12" bgcolor="#EECCFF">&nbsp;</td>
        <td align="center" width="12" bgcolor="#EECCFF">&nbsp;</td>
        
    </tr>
<TBODY>
    <% set PropDescs = DocType.PropertyDescriptions 
           
           ' enumerate through the Doctype properties, to display their name and control to enter the value
           for i = 1 to PropDescs.Count
           set PropDesc = PropDescs(i)
        if PropDesc.Name <> "idmDocCheckouts" then
        %>
    <tr>
    <td valign=top align=right></td>
    
    <td valign=top align=left>
    <% 
        
    IsReadOnly = PropDesc.GetState(Application("idmPropReadOnly"))
    if PropDesc.GetState(Application("idmPropRequired")) then ' this is a required property
    %>
    <font color="#FF0000" size="5"><strong>*</strong></font>
    <% 
    end if
    if PropDesc.GetState(Application("idmPropVersion")) then ' this is a Version property
    %>
    <font color="#FF0000" size="3"><strong>v</strong></font>
    <%  end if %>
    </td>

    <td valign=top><em><%= PropDesc.Label %>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</em></td>
    <td valign=top>
    <% value = ""
       if Status <> "" and Status <> "1" then
            value = SubmittedValues(i)
       end if
       propName = UCase(PropDesc.Name)
       if value = "" then
        if PropDesc.GetState(Application("idmPropMultiValue")) then ' ==========================
            StrVal=""
            if Request.Form(propName).Count then
                for p=1 to Request.Form(propName).Count ' display new added values
                    if not (Request.Form(propName)(p) = "") then
                        StrVal = StrVal + Request.Form(propName)(p) + ","
                    end if
                next
            else
                if not isNull(PropDesc.DefaultValue) then
                    StrVal = PropDesc.FormatValue(PropDesc.DefaultValue)
                end if 
            end if
                            
            value = StrVal
        else
            value = Request.Form(propName)
            if isNull(value) OR value = "" then
                if not isNull(PropDesc.DefaultValue) then
                    value = PropDesc.FormatValue(PropDesc.DefaultValue)
                else
                    value = ""
                end if
            end if
        end if
       end if

       ' depending on property type, there is a different control to enter the property value 
       if IsReadOnly then 
            v = PropDesc.DefaultValue
            if IsNull(v) then 
                v = ""
            else 
                v = PropDesc.FormatValue(v) 
            end if
            if v = "Null" then %>
            <%= value %>
            <% else %>
            <%= v %>
            <% end if

       ' case of multivalue property ========================
       elseif PropDesc.GetState(Application("idmPropMultiValue")) then 
            if ( PropDesc.GetState(Application("idmPropMustPick"))) then
            ' should set the selected values and display all Choices
            ' is there a selection list for this Multi Value Prop ?
             IsChoicePaging = PropDesc.GetState(Application("idmChoicePaging"))
             if IsChoicePaging  then 
                set Choices = PropDesc.Choices
                set oPaging = Choices.Paging
                iPage=1
                'PageSize=50 ' update this value along with "if Choices.Count=50 then" below
                'oPaging.Size = PageSize ' number of choices to retrieve, default is 50
                call oPaging.NextPage(NULL,1) ' idmForward is default
                Count=Choices.Count

            %>
                <%= value %> <br>
                <select multiple name="<%= propName %>" size="3">
            <%
                ' if property not required, allow also empty string as choice =======
                if (not PropDesc.GetState(Application("idmPropRequired"))) then 
                %>
                <option value=""> </option>
                <%
                end if
                ' =====
                do until Count=0
                    for k=iPage to Choices.Count
                        ChoiceStrVal = PropDesc.FormatValue(Choices.Item(k).Value)
            %>
            <option value="<%= ChoiceStrVal %>"
                    <% 
                    if Request.Form(propName).Count > 0 then ' ===== check against FORMs param 
                        for m=1 to Request.Form(propName).Count
                            ThisStrVal = Request.Form(propName)(m)
                            if ChoiceStrVal=ThisStrVal then %> selected
                         <% end if
                        next
                    else    ' ====== check if the property has a default value
                        if not isNull(PropDesc.DefaultValue) then
                            ThisStrVal = PropDesc.FormatValue(PropDesc.DefaultValue)
                            if ChoiceStrVal=ThisStrVal then %> selected
                            <% end if
                        end if 
                    end if %>
                    > <%= ChoiceStrVal %> </option>
            <%
                    next
                ' need to check if there are MORE choices to display
                  if Choices.Count=50 then  ' check against preset PageSize
                    iPage=2 ' to skip first element in the list (it has the search  key)
                    call oPaging.NextPage(Choices.Item(k - 1).Value, 1)
                    Count=Choices.Count
                  else Count=0
                  end if
                loop
            %>

                </select>
            <% end if
            else ' MayPick values entered in MultiValue Property page ================
            %>
                <%= value %>
                <% 
                if Request.Form(propName).Count > 0 then
                    for p=1 to Request.Form(propName).Count %>  
                    <INPUT TYPE=hidden name="<%=propName%>" value="<%= Request.Form(propName)(p) %>"> 
                    <% next
                else    ' ====== check if the property has a default value
                    if not isNull(PropDesc.DefaultValue) then
                        ThisStrVal = PropDesc.FormatValue(PropDesc.DefaultValue)
                        %>
                    <INPUT TYPE=hidden name="<%=propName%>" value="<%= ThisStrVal %>"> 
                        <%
                    end if 
                end if  
                 %>
            
            <% end if %>
                
        <%
        ' case of single value property with the type: must set by ID (not by value) ====================
        elseif PropDesc.GetState(Application("idmPropMustSetByID")) then
            ' check if there is a selection list
            IsChoicePaging = PropDesc.GetState(Application("idmChoicePaging"))
            if IsChoicePaging   then 
                set Choices = PropDesc.Choices 
                set oPaging = Choices.Paging
                call oPaging.NextPage(NULL,1) ' idmForward is default
                Count=Choices.Count
                if Request.Form(propName).Count > 0 then ' ===== check against FORMs param
                    thisVal=PropDesc.FormatValue(CLng(Request.Form(propName)))
                else
                    thisVal= PropDesc.DefaultValue
                end if
        %>
            <select name="<%= PropDesc.Name %>" size="1">
        <%
                for k=1 to Choices.Count
                    ChStrVal = PropDesc.FormatValue(Choices.Item(k).Value)

        %>
                
            <option value="<%= Choices.Item(k).Value %>" <% if thisVal=ChStrVal then %> selected <%end if%> > <%= ChStrVal %> </option>
        <%
                next
        %>
            </select>
        <%
            end if
        ' case of single value property w/ selection list
        elseif PropDesc.GetState(Application("idmPropHasCVL")) then 
            ' check if there is a selection list
            IsChoicePaging = PropDesc.GetState(Application("idmChoicePaging"))
            if IsChoicePaging   then 
                set Choices = PropDesc.Choices
                set oPaging = Choices.Paging
                iPage=1
                'PageSize=50 ' update this value along with "if Choices.Count=50 then" below
                'oPaging.Size = PageSize ' number of choices to retrieve, default is 50
                call oPaging.NextPage(NULL,1) ' idmForward is default
                Count=Choices.Count
                if Request.Form(propName).Count > 0 then ' ===== check against FORMs param
                    thisVal=Request.Form(propName) ' if date, it is already formatted
                else
                    thisVal=value
                end if
        %>
            <select name="<%= PropDesc.Name %>" size="1">
                <% 
                if (not PropDesc.GetState(Application("idmPropRequired"))) then %>
            <option value=""<% if ""=thisVal then %> selected <%end if%> > </option>
                <% end if %>
        <%
                do until Count=0
                    for k=iPage to Choices.Count
                        StrVal = PropDesc.FormatValue(Choices.Item(k).Value)
        %>
            <option value="<%= StrVal %>" <% if UCase(StrVal)=UCase(thisVal) then %> selected <%end if%> > <%= StrVal %> </option>
        <%
                    next
                ' need to check if there are MORE choices to display
                  if Choices.Count=50 then  ' check against PageSize
                    iPage=2 ' to skip the search key element
                    call oPaging.NextPage(Choices.Item(k - 1).Value, 1)
                    Count=Choices.Count
                  else Count=0
                  end if
                loop
        %>
            </select>
        <%
            end if
         %>
        
    <% elseif PropDesc.TypeID = Application("idmTypeBoolean") then %>
        <select name="<%= Prop.Name %>" size="1">
            <option value="1" <% if value = 1 then %>selected<% end if %>>True</option>
            <option value="0" <% if value = 0 then %>selected<% end if %>>False</option>
        </select>

    <% elseif FALSE then ' PropDesc.GetState(Application("idmChoice")) then
        set Choices = PropDesc.Choices %>
        <select name="<%= Prop.Name %>" size="1">
            <% if IsNull(value) then %>
                <option value="" selected>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>
            <% end if %>
            <% for each Choice in Choices
                if value then %>
                <option value="<%= Choice.ID %>" <% if CLng(value) = Choice.ID then %>selected<% end if %>><%= Choice.Value %>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>
                <% else %>
                <option value="<%= Choice.ID %>"><%= Choice.Value %>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>
                <%  end if %>
            <% next %>
        </select>

    <% 
    ' case of single value string entered as input TEXT ====================
    else 
        FieldSize = PropDesc.Size
    %>
        <input type="text" size="50" name="<%= PropDesc.Name %>"
            <% if FieldSize > 0 then %>
            maxlength=<%= FieldSize %>
            <% end if %>
            <%
            ' check if the value comes from the request form or the already set value
            if Request.Form(propName).Count > 0 then ' ===== check against FORMs param
            %>
                value="<%= Request.Form(propName) %>"
            <% else %>
                value="<%= value %>"
            <% end if %>
            
            <% if PropDesc.TypeID = Application("idmTypeDate") then %>
            onBlur="CheckDate(this, '<%=value%>')"
            <% elseif PropDesc.TypeID = Application("idmTypeLong") or PropDesc.TypeID = Application("idmTypeShort") _ 
             or PropDesc.TypeID = Application("idmTypeSingle") _
             or PropDesc.TypeID = Application("idmTypeUnsignedShort") or PropDesc.TypeID = Application("idmTypeUnsignedLong")   then %>
            onBlur="CheckInteger(this, '<%=value%>')"
            <% end if %>

            <% if PropDesc.GetState(Application("idmPropRequired")) then %>
            onChange="CheckSelected(this)"
            <% end if %>
            >
    <% end if %>
    </td>

    <td valign=top nowrap>
    <% 
    ' in the ShowHints Column, display either the dataType string or the MultiValueProp button
      if not IsReadOnly then 
        if PropDesc.GetState(Application("idmPropMultiValue")) then 
            if (not PropDesc.GetState(Application("idmPropMustPick"))) then 
         %>
         <a target="View" HREF="javascript:MayPickMVProperty('<%=Ident%>','<%=PropDesc.Name%>',<%=ObjType%>)">
    <img alt="Modify MultiValued Property" src="images/smodify.gif" align=bottom border=0 width=24 height=22></a>
            <% end if %>
        <% elseif ShowHintsFlag then %>
            <font size="2">(<%= ConvertToHints(ObjType, PropDesc) %>)</font>
        <% end if %>
    <% end if %>
    </td>
    <td valign=top nowrap></td>

    </tr>
    
    <% 
        end if
    next %>
</table>
<%
if IEBrowser then %>
<br>
<% else %>
<hr>
<% end if %>
<table border="0" cellpadding="0" cellspacing="1">
    <tr>
    <td width="30" valign=bottom align=right></td>
    <td>
    <% if not IsVirtual then %>
    <a href="javascript:DoSubmit()"><img onClick="javascript:DoSubmit()" src="images/handdoc.gif" alt="Proceed to Choose a Document"  align=bottom border=0 width=47 height=43></a><em><strong>Choose a document...</strong></em>
    <% end if %>
    </td>
    </tr>
</table>
</form>

<SCRIPT LANGUAGE="JavaScript">
<!--
document.propenter.formloaded.value = "1";
//-->
</SCRIPT>

<SCRIPT LANGUAGE="JavaScript">
<!--
function DoSubmit()
{
    document.propenter.submitProps.value="1";
    document.propenter.SubmitFlag.value = "1";
    document.propenter.submit();
}
//-->
</SCRIPT>

<!-- #include file="checkutil.asp" -->
<!-- #include file="mz_checksel.asp" -->

<%
    Response.End
    end if
    '
    '  We have all the properties we need,
    '  Display the properties for viewing ( in non edit mode)
    '  Display the upload form.
    '
%>
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html">
<meta name="GENERATOR" content="">
<title>Add Document: Select File</title>
</head>
<body bgcolor="#FFFFFF">

<font size="+2"><strong>Upload Document</strong></font><br>
<strong><em>Add document to library '<%= Server.HTMLEncode(LibraryObj.Label) %>' with doc type '<%= Server.HTMLEncode(DocClass) %>.'</em></strong>
<p>

<SCRIPT LANGUAGE="JavaScript">
<!--
function DoSubmit()
{
    document.docupload.submit();
}
//-->
</SCRIPT>
<% set PropDescs = DocType.PropertyDescriptions %>


<FORM NAME="docupload" ACTION="docUpload.dll" METHOD="POST" ENCTYPE="multipart/form-data">
<!-- begin hidden parameters 
   - these parameters are passed to the actual add isapi dll-->
            <input type=hidden name="library" value="<%=LibraryObj.Name%>">
            <input type=hidden name="doctype" value="<%=DocClass%>">
            <input type=hidden name="logonid" value="<%=LibraryLogonID%>">
<% for each x in Request.Form
    PropName = x
    for i = 1 to Request.Form(x).Count 
    PropValue= Request.Form(x).item(i) 
        if Left(PropName,3) = "IDM" then %>
            <input type=hidden name="property" value="<%=PropName%>">
            <input type=hidden name="value" value="<%=PropValue%>"><%
        else %>
            <input type=hidden name="<%=PropName%>" value="<%=PropValue%>">
<%
        end if
    next 
   next %>

<!-- end hidden parameters -->
<table border=0 width=400>
  <tr>
<% ContentPathname = Session("ContentPathname")
    if not ContentPathname = "" AND not ContentPathname = "/" then
        set FolderObj = LibraryObj.GetObject(Application("idmObjTypeFolder"),ContentPathname)
%>
    <td align=left>
      <input type=checkbox name="file_in_folder" CHECKED> Add document to folder <%=Server.HTMLEncode(FolderObj.Label) %>
      <input type=hidden name="folder" value="<%=ContentPathname%>">
    </td>
<%
   end if
%>
  </tr>
  <tr>
    <td>
      <input type=checkbox name="index" CHECKED> Index document for content searching.
    </td>
  </tr>
  <tr>
    <td>
      <input type=checkbox name="security"> Modify security. 
    </td>
  </tr>
</table>
    <input type="file" name="filename" value="" size=60>
<br><br><hr>
<a href="javascript:DoSubmit()"><img border=0 type="submit" src="images/update.gif" value="Add Document"></a><strong><em>Add Document</em></strong>
</form>
</body>
</html>